package top.kaoshanji.r1ch05a;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

/**
 * @author kaoshanji
 * ^_^
 * create time 2025/5/5 20:00
 */
public class InjectFunTest {

    public ApplicationContext context = null;

    @BeforeMethod
    public void setUp() {
        context = new ClassPathXmlApplicationContext("r1ch05a/beans.xml");
    }

    /**
     * 代码清单test-r1ch05a-01：测试一下lookup方法注入
     */
    @Test
    public void lookupMethod() {
        MagicBoss magicBoss = (MagicBoss)context.getBean("magicBoss");

        Assert.assertNotSame(magicBoss.getCar(), magicBoss.getCar());
    }

    /**
     * 代码清单test-r1ch05a-02：测试一下replaced方法替换
     */
    @Test
    public void replacedMethod() {
        Boss1 boss1 = (Boss1)context.getBean("boss1");

        Assert.assertEquals(boss1.getCar().getBrand(), "美人豹");
    }

}
